﻿namespace homewizard
{
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class showdata : Page
    {
        protected Button Button1;
        protected DropDownList drpid;
        protected HtmlForm form1;
        protected GridView grd;

        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
            SqlCommand command = new SqlCommand("Truncate table [homewizard_test2user].[WebServiceList] ", connection);
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }

        protected void drpid_SelectedIndexChanged(object sender, EventArgs e)
        {
            int num = Convert.ToInt32(this.drpid.SelectedValue);
            string selectCommandText = "";
            DataTable dataTable = new DataTable();
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
            SqlCommand command = new SqlCommand();
            if (num != 0x3e8)
            {
                selectCommandText = "select top(" + num + ")  *From [homewizard_test2user].[WebServiceList] order by DateTime desc";
            }
            else
            {
                selectCommandText = "select *From [homewizard_test2user].[WebServiceList] order by DateTime desc";
            }
            selectConnection.Open();
            new SqlDataAdapter(selectCommandText, selectConnection).Fill(dataTable);
            this.grd.DataSource = dataTable;
            this.grd.DataBind();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["isLoggedIn"] == null)
            {
                base.Response.Redirect("~/hwLogin.aspx?ReturnUrl=showdata.aspx");
            }
        }
    }
}

